package com.chuangsi.project.admin.controller.admin;


import com.chuangsi.common.utils.poi.ExcelUtil;
import com.chuangsi.framework.aspectj.lang.annotation.Log;
import com.chuangsi.framework.aspectj.lang.enums.BusinessType;
import com.chuangsi.framework.web.controller.BaseController;
import com.chuangsi.framework.web.domain.ResultObject;
import com.chuangsi.framework.web.page.TableDataInfo;
import com.chuangsi.project.admin.dto.admin.plan.PlanPageQueryReqDto;
import com.chuangsi.project.admin.dto.admin.plan.PlanPageQueryResDto;
import com.chuangsi.project.admin.dto.admin.plan.PlanSetReqDto;
import com.chuangsi.project.admin.service.IPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 计划 前端控制器
 * </p>
 *
 * @author 
 * @since 2024-03-30
 */
@Api(tags="计划")
@RestController
@RequestMapping("/adminApi/plan")
public class PlanController extends BaseController {

    @Autowired
    private IPlanService planService;

    @ApiOperation(value = "分页查询", response = PlanPageQueryResDto.class)
    @GetMapping("/list")
    public TableDataInfo pageQuery(PlanPageQueryReqDto dto) {
        startPage();
        List<PlanPageQueryResDto> list = planService.pageQuery(dto);
        return getDataTable(list);
    }

    @ApiOperation(value = "导出")
    @Log(title = "计划列表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(HttpServletResponse response, PlanPageQueryReqDto dto) {
        List<PlanPageQueryResDto> list = planService.pageQuery(dto);
        ExcelUtil<PlanPageQueryResDto> util = new ExcelUtil<>(PlanPageQueryResDto.class);
        util.exportExcel(response, list, "计划记录","计划记录");
    }

    @ApiOperation(value = "设置计划")
    @PostMapping("/setPlan")
    public ResultObject<Void> setPlan(@RequestBody @Valid PlanSetReqDto req){
        planService.setPlan(req);
        return ResultObject.ok("设置成功");
    }


}
